<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>中医体质辨识<small>体质评测</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>中医体质辨识</el-breadcrumb-item>
            <el-breadcrumb-item>体质评测</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="项目编码/项目名称" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column prop="danganhao" align="center" label="档案号"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="date" label="评估日期" align="center"></el-table-column>
                <el-table-column prop="pinghe" label="平和质" align="center"></el-table-column>
                <el-table-column prop="qixu" label="气虚质" align="center"></el-table-column>
                <el-table-column prop="yinxu" label="阴虚质" align="center"></el-table-column>
                <el-table-column prop="tanshi" label="痰湿质" align="center"></el-table-column>
                <el-table-column prop="shire" label="湿热质" align="center"></el-table-column>
                <el-table-column prop="xueyu" label="血瘀质" align="center"></el-table-column>
                <el-table-column prop="qiyu" label="气郁质" align="center"></el-table-column>
                <el-table-column prop="tebin" label="特禀质" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button><br/>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button><br/>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增评测" :visible.sync="dialogFormVisible">

                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本概况" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="评估日期">
                                                <el-input v-model="formData.date"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="测评问题" name="second">
                                <el-form label-position="right" label-width="100px">
                                    <!--相关试题内容-->
                                    <el-col :span="12" v-for="(item,index) in problem">
                                        <el-radio-group  v-model="formData.daan[index]" >
                                            <el-form-item :label="item.question" >
                                                <el-radio label="A"></el-radio>
                                                <el-radio label="B"></el-radio>
                                                <el-radio label="C"></el-radio>
                                                <el-radio label="D"></el-radio>
                                            </el-form-item>
                                        </el-radio-group>
                                    </el-col>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                        <el-button @click="resetForm('dataAddForm')">重置</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑评测" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="档案号" prop="code">
                                    <el-input v-model="formData.danganhao"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="姓名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="评估日期" prop="name">
                                    <el-input v-model="formData.date"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="平和质" prop="type">
                                    <el-select v-model="formData.pinghe">
                                        <el-option label="是" :value="1"></el-option>
                                        <el-option label="否" :value="0"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="气虚质" prop="type">
                                    <el-select v-model="formData.qixu">
                                        <el-option label="是" :value="1"></el-option>
                                        <el-option label="否" :value="0"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="阴虚质" prop="type">
                                    <el-select v-model="formData.yinxu">
                                        <el-option label="是" :value="1"></el-option>
                                        <el-option label="否" :value="0"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="痰湿质" prop="type">
                                    <el-select v-model="formData.tanshi">
                                        <el-option label="是" :value="1"></el-option>
                                        <el-option label="否" :value="0"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="热湿质" prop="type">
                                    <el-select v-model="formData.shire">
                                        <el-option label="是" :value="1"></el-option>
                                        <el-option label="否" :value="0"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="血瘀质" prop="type">
                                    <el-select v-model="formData.xueyu">
                                        <el-option label="是" :value="1"></el-option>
                                        <el-option label="否" :value="0"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="气郁质" prop="type">
                                    <el-select v-model="formData.qiyu">
                                        <el-option label="是" :value="1"></el-option>
                                        <el-option label="否" :value="0"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="特禀质" prop="type">
                                    <el-select v-model="formData.tebin">
                                        <el-option label="是" :value="1"></el-option>
                                        <el-option label="否" :value="0"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {
                daan: []//答案
            },//表单数据
            tableData: [],
            problem: [],//问题

            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                /* code: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                 name: [{required: true, message: '项目名称为必填项', trigger: 'blur'}],
                 sex: [{required: true, message: '项目性别为必填项', trigger: 'blur'}],
                 age: [{required: true, message: '适用年龄为必填项', trigger: 'blur'}],
                 type: [{required: true, message: '项目类型为必填项', trigger: 'blur'}],
                 price: [{required: true, message: '项目价格为必填项', trigger: 'blur'}]*/
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //编辑
            handleEdit() {
                this.$refs['dataEditForm'].validate((valid) => {
                    if (valid) {
                        axios.post("/zhongyi/update.do", this.formData).then((res) => {
                            if (res.data.flag) {
                                this.dialogFormVisible4Edit = false;
                                this.findPage();
                                this.$message.success("编辑成功");
                            }
                        })

                    } else {
                        return false;
                    }
                });
            },
            //添加
            handleAdd() {
                console.log(this.formData);
                axios.post("/zhongyi/add.do", this.formData).then((res) => {
                    if (res.data.flag) {
                        this.dialogFormVisible = false;
                        this.findPage();
                        this.$message.success("添加成功");
                    } else {
                        this.dialogFormVisible = false;
                        this.findPage();
                        this.$message.error(res.data.message);
                    }
                })

            }
            ,
            //分页查询
            findPage() {
                axios.post("/zhongyi/findAll.do", this.pagination).then((res) => {
                    console.log(res.data)
                    if (res.data.flag) {

                        this.dataList = res.data.data.list;
                        ;
                        this.pagination.total = res.data.data.total;
                    }
                })
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                this.dialogFormVisible = true;
                this.resetForm('dataAddForm');
                //查询对应的问题
                axios.post('/zhongyi/getProblem.do').then((res) => {
                    this.problem = res.data.data;
                    for (var i = 0; i <this.problem.length;i++){
                        this.formData.daan[i] = 'A'
                    }
                })
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.dialogFormVisible4Edit = true;
                this.formData = row;
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            resetForm(formName) {
                // this.$refs[formName].resetFields();
            },
            // 删除
            handleDelete(row) {
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/zhongyi/delete.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            this.findPage();
                            this.$message.success("删除成功");
                        } else {
                            this.$message.error(res.data.message);
                        }
                    }).catch((error) => {
                        if (error == 'Error: Request failed with status code 403') {
                            this.$message.error("暂无操作权限")
                        }
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            }
        }
    })
</script>
</html>